package com.aaa.controller;

import com.aaa.service.L_FieldTripService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/trip")
public class L_FieldTripController {
    @Autowired
    private L_FieldTripService service;

    @RequestMapping("/select")
    public String toList(){
        return "Declarationmanagement/fieldtrip";
    }

    @RequestMapping("/list")
    @ResponseBody
    public Object list(@RequestBody Map map){
        List<Map> list=service.getAll(map);
        System.out.println(map.get("inspection"));
        Integer total=service.getCount(map);
        Map maps=new HashMap();
        maps.put("data",list);
        maps.put("total",total);
        return maps;
    }
    @RequestMapping("/add")
    public String add(){
        return  "Declarationmanagement/EditField";
    }
    @RequestMapping("/return")
    public String returnClick(){
        return  "Declarationmanagement/fieldtrip";
    }

//删除实地考察
    @RequestMapping("/del")
    public String del(Integer id){
        System.out.println(id);
        service.del(id);
        return  "redirect:select";
    }
//获取单位命称
    @RequestMapping("/DWname")
    @ResponseBody
    public Map DWname(){
        Map map=new HashMap();
        map.put("options",service.DWname());
       return map;
    }

    //新增实地考察
    @RequestMapping("/xinzeng")
    @ResponseBody
    public Object xinzeng(@RequestBody Map map){//"danwei":danwei,"textarea":textarea,"region":region,"id":id
        System.out.println(map);
        List<Map> list=service.inscore(map);//查询公司表里的考查分数
        System.out.println(list.get(0)+"     list");
        System.out.println(list.get(0)+"     size");
        if (list.get(0)!=null) {
            //如果存在就修改考查分数
            service.setinscore(map);
        }else if(list.get(0)==null){
            service.addinscore(map);//如果不存在,给总表里添加考察分数
        }
    Integer i=service.xinzeng(map);
    if (i>0){
        return  "aaa";
    }else {
        return  null;
    }
    }


    @RequestMapping("/chachong")
    @ResponseBody
    public  Object chachong(@RequestBody Map map){
        System.out.println(map.get("danwei"));
        int i=service.chachong(map);
        return i;
    }
}
